{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}D:\users\llochner\Dropbox\JOINT PROJECTS\JPE_Child_Devp_2020\FINAL_Replication_CLMP_JPE\code\estimation\basics_rel_demand\logs/2_create_child_data.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res} 9 Jul 2025, 17:15:45
{txt}
{com}. 
. 
. *******************************************************************
. *************   A. import & save PSID data for children   *********
. *******************************************************************
. *** Read panel data for all children in CDS (observations by kid-year)
. clear
{txt}
{com}. use "$data/ChildPanelCDS.dta"
{txt}(Written by R.              )

{com}. rename *, lower
{res}{txt}
{com}. 
. *******************************************************************
. *************  B. Initial variable construction   *****************
. *******************************************************************
. 
. 
. *drop PSID state, keep FIPS 
. drop state
{txt}
{com}. rename stfips  state                         // rename state fips code 'state' for merging
{res}{txt}
{com}. rename childcare_exp chcare_ann           // rename annual childcare expenditures from main PSID survey
{res}{txt}
{com}. rename m_pc_st m_pc97                                                    // rename "mom" passage comprehension score from 1997
{res}{txt}
{com}. 
. * Generate educational categories
. gen med_cat = .
{txt}(36,849 missing values generated)

{com}. replace med_cat=1 if med_hsd==1
{txt}(4,510 real changes made)

{com}. replace med_cat=2 if med_hs==1
{txt}(12,803 real changes made)

{com}. replace med_cat=3 if med_scoll==1
{txt}(11,011 real changes made)

{com}. replace med_cat=4 if med_collplus==1
{txt}(8,459 real changes made)

{com}. 
. gen fed_cat = .
{txt}(36,849 missing values generated)

{com}. replace fed_cat=1 if fed_hsd==1
{txt}(2,550 real changes made)

{com}. replace fed_cat=2 if fed_hs==1
{txt}(7,912 real changes made)

{com}. replace fed_cat=3 if fed_scoll==1
{txt}(4,704 real changes made)

{com}. replace fed_cat=4 if fed_collplus==1
{txt}(6,383 real changes made)

{com}. 
. duplicates report kid year

{p 0 4}{txt}Duplicates in terms of {res} kid year{p_end}

{txt}{hline 10}{c TT}{hline 27}
   copies {c |} observations       surplus
{hline 10}{c +}{hline 27}
        1 {c |}        {res}36849             0
{txt}{hline 10}{c BT}{hline 27}

{com}. 
. 
. 
. * Generate some age-related variables
. 
. gen num_13plus = num_child - num_0_12
{txt}
{com}. 
. gen old_child = (num_13plus>=1)
{txt}
{com}. replace old_child=. if num_13plus==.
{txt}(0 real changes made)

{com}. 
. gen old_child_2plus = (num_13plus>=2)
{txt}
{com}. replace old_child_2plus=. if num_13plus==.
{txt}(0 real changes made)

{com}. 
. 
. gen age9_12 = (age>=9 & age<=12)
{txt}
{com}. replace age9_12=. if age==.
{txt}(0 real changes made)

{com}.         
. 
. *Impute grandparents or other relatives in HH using the lag for non-interview years after 1997
. 
. xtset kid year
{res}{txt}{col 8}panel variable:  {res}kid (unbalanced)
{txt}{col 9}time variable:  {res}{col 25}year, 1997 to 2007
{txt}{col 17}delta:  {res}1 unit
{txt}
{com}. replace biol_grand_hh=L1.biol_grand_hh if year==1998|year==2000|year==2002|year==2004|year==2006
{txt}(15,622 real changes made)

{com}. replace older_relative_hh=L1.older_relative_hh if year==1998|year==2000|year==2002|year==2004|year==2006
{txt}(15,622 real changes made)

{com}. 
. 
. 
. 
. *Save full child's panel
. save "$temp/parchild1.dta", replace 
{txt}(note: file D:\users\llochner\Dropbox\JOINT PROJECTS\JPE_Child_Devp_2020\FINAL_Replication_CLMP_JPE\code\estimation\basics_rel_demand\temp_data/parchild1.dta not found)
file D:\users\llochner\Dropbox\JOINT PROJECTS\JPE_Child_Devp_2020\FINAL_Replication_CLMP_JPE\code\estimation\basics_rel_demand\temp_data/parchild1.dta saved

{com}. 
. 
. 
. **********************************************************************************
. * C. Merge predicted wages from Census using occupation, education, race, state  *
. ***********************************************************************************
. 
. *** Prepare predicted wages for merge for mothers and fathers
. 
. * Use minor occupation categorization
. 
. 
. 
. use "$data/predicted_lnwage3", clear
{txt}
{com}. *keep predicted wages for mothers
. keep if  female==1
{txt}(38,977 observations deleted)

{com}. *Rename variables to m_*
. rename occ_minor m_occ_minor
{res}{txt}
{com}. rename predicted_*  m_pred_*
{res}{txt}
{com}. rename race m_white
{res}{txt}
{com}. rename n_obs m_n_obs
{res}{txt}
{com}. sort m_occ_minor state educ m_white
{txt}
{com}. save "$temp/mother_occupation.dta", replace 
{txt}(note: file D:\users\llochner\Dropbox\JOINT PROJECTS\JPE_Child_Devp_2020\FINAL_Replication_CLMP_JPE\code\estimation\basics_rel_demand\temp_data/mother_occupation.dta not found)
file D:\users\llochner\Dropbox\JOINT PROJECTS\JPE_Child_Devp_2020\FINAL_Replication_CLMP_JPE\code\estimation\basics_rel_demand\temp_data/mother_occupation.dta saved

{com}. 
. 
. use "$data/predicted_lnwage3", clear
{txt}
{com}. *keep predicted wages for fathers
. keep if  female==0
{txt}(34,986 observations deleted)

{com}. *Rename variables to f_*
. rename occ_minor f_occ_minor
{res}{txt}
{com}. rename predicted_* f_pred_*
{res}{txt}
{com}. rename race f_white
{res}{txt}
{com}. rename n_obs f_n_obs
{res}{txt}
{com}. sort f_occ_minor state educ f_white
{txt}
{com}. save "$temp/father_occupation.dta", replace 
{txt}(note: file D:\users\llochner\Dropbox\JOINT PROJECTS\JPE_Child_Devp_2020\FINAL_Replication_CLMP_JPE\code\estimation\basics_rel_demand\temp_data/father_occupation.dta not found)
file D:\users\llochner\Dropbox\JOINT PROJECTS\JPE_Child_Devp_2020\FINAL_Replication_CLMP_JPE\code\estimation\basics_rel_demand\temp_data/father_occupation.dta saved

{com}. 
. 
. 
. *Merge predicted wages with the panel of children
. use "$temp/parchild1.dta", clear
{txt}(Written by R.              )

{com}. 
. *Occupation is not reported in 2002: use occupation in 2003 if available 
. //- if 2003 occupation missing - use 2001 occupation
. xtset kid year
{res}{txt}{col 8}panel variable:  {res}kid (unbalanced)
{txt}{col 9}time variable:  {res}{col 25}year, 1997 to 2007
{txt}{col 17}delta:  {res}1 unit
{txt}
{com}. replace m_occ_minor=F1.m_occ_minor if year==2002
{txt}(2,440 real changes made)

{com}. replace m_occ_minor=L1.m_occ_minor if year==2002 & m_occ_minor==.
{txt}(329 real changes made)

{com}. 
. replace f_occ_minor=F1.f_occ_minor if year==2002
{txt}(1,818 real changes made)

{com}. replace f_occ_minor=L1.f_occ_minor if year==2002 & f_occ_minor==.
{txt}(290 real changes made)

{com}. 
. *Generate consistent education category for merge with mother's predicted wages
. generate educ=.
{txt}(36,849 missing values generated)

{com}. replace educ=0 if m_ed=="<12"
{txt}(4,510 real changes made)

{com}. replace educ=1  if m_ed=="12"
{txt}(12,803 real changes made)

{com}. replace educ=2  if m_ed=="13-15"
{txt}(11,011 real changes made)

{com}. replace educ=3  if m_ed=="16"
{txt}(4,961 real changes made)

{com}. replace educ=4  if m_ed==">16"
{txt}(3,498 real changes made)

{com}. 
. sort m_occ_minor state educ m_white
{txt}
{com}. merge m:1 m_occ_minor state educ m_white using "$temp/mother_occupation.dta", keep(match master)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}          19,618
{txt}{col 9}from master{col 30}{res}          19,618{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}          17,231{txt}  (_merge==3)
{col 5}{hline 41}

{com}. tab _merge

                 {txt}_merge {c |}      Freq.     Percent        Cum.
{hline 24}{c +}{hline 35}
        master only (1) {c |}{res}     19,618       53.24       53.24
{txt}            matched (3) {c |}{res}     17,231       46.76      100.00
{txt}{hline 24}{c +}{hline 35}
                  Total {c |}{res}     36,849      100.00
{txt}
{com}. 
. drop _merge educ
{txt}
{com}. 
. 
. *Generate consistent education category for merge with father's predicted wages 
. generate educ=.
{txt}(36,849 missing values generated)

{com}. replace educ=0 if f_ed=="<12"
{txt}(2,550 real changes made)

{com}. replace educ=1  if f_ed=="12"
{txt}(7,912 real changes made)

{com}. replace educ=2  if f_ed=="13-15"
{txt}(4,704 real changes made)

{com}. replace educ=3  if f_ed=="16"
{txt}(3,744 real changes made)

{com}. replace educ=4  if f_ed==">16"
{txt}(2,639 real changes made)

{com}. 
. sort f_occ_minor state educ f_white
{txt}
{com}. merge m:1 f_occ_minor state educ f_white using "$temp/father_occupation.dta", keep(match master)
{res}{txt}(label statefip_lbl already defined)
(label vrace already defined)
(label vedl already defined)

{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}          23,952
{txt}{col 9}from master{col 30}{res}          23,952{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}          12,897{txt}  (_merge==3)
{col 5}{hline 41}

{com}. tab _merge

                 {txt}_merge {c |}      Freq.     Percent        Cum.
{hline 24}{c +}{hline 35}
        master only (1) {c |}{res}     23,952       65.00       65.00
{txt}            matched (3) {c |}{res}     12,897       35.00      100.00
{txt}{hline 24}{c +}{hline 35}
                  Total {c |}{res}     36,849      100.00
{txt}
{com}. 
. ******************************************************************
. 
. drop _merge educ 
{txt}
{com}. 
. sort state year 
{txt}
{com}. save "$temp/parchild2.dta", replace
{txt}(note: file D:\users\llochner\Dropbox\JOINT PROJECTS\JPE_Child_Devp_2020\FINAL_Replication_CLMP_JPE\code\estimation\basics_rel_demand\temp_data/parchild2.dta not found)
file D:\users\llochner\Dropbox\JOINT PROJECTS\JPE_Child_Devp_2020\FINAL_Replication_CLMP_JPE\code\estimation\basics_rel_demand\temp_data/parchild2.dta saved

{com}. 
. 
. *******************************************************************
. ******** D.  Merge with state-year price data ***********
. *******************************************************************
. 
. clear
{txt}
{com}. use "$data/p_extendedcosts.dta"
{txt}
{com}. 
. drop state_year
{txt}
{com}. 
. rename stateid state
{res}{txt}
{com}. rename all p_all
{res}{txt}
{com}. rename goods p_goods
{res}{txt}
{com}. rename servo p_serv
{res}{txt}
{com}. 
. 
. 
. sort state year
{txt}
{com}. 
. merge 1:m state year using "$temp/parchild2.dta", keep(match using)
{res}{txt}{p 0 7 2}
(note: variable
year was 
int, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
state was 
byte, now long to accommodate using data's values)
{p_end}

{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               0
{txt}{col 5}matched{col 30}{res}          36,849{txt}  (_merge==3)
{col 5}{hline 41}

{com}. tab year _merge

    {txt}Survey {c |}   _merge
      year {c |} matched ( {c |}     Total
{hline 11}{c +}{hline 11}{c +}{hline 10}
      1997 {c |}{res}     3,349 {txt}{c |}{res}     3,349 
{txt}      1998 {c |}{res}     3,350 {txt}{c |}{res}     3,350 
{txt}      1999 {c |}{res}     3,350 {txt}{c |}{res}     3,350 
{txt}      2000 {c |}{res}     3,350 {txt}{c |}{res}     3,350 
{txt}      2001 {c |}{res}     3,350 {txt}{c |}{res}     3,350 
{txt}      2002 {c |}{res}     3,350 {txt}{c |}{res}     3,350 
{txt}      2003 {c |}{res}     3,350 {txt}{c |}{res}     3,350 
{txt}      2004 {c |}{res}     3,350 {txt}{c |}{res}     3,350 
{txt}      2005 {c |}{res}     3,350 {txt}{c |}{res}     3,350 
{txt}      2006 {c |}{res}     3,350 {txt}{c |}{res}     3,350 
{txt}      2007 {c |}{res}     3,350 {txt}{c |}{res}     3,350 
{txt}{hline 11}{c +}{hline 11}{c +}{hline 10}
     Total {c |}{res}    36,849 {txt}{c |}{res}    36,849 
{txt}
{com}. drop _merge
{txt}
{com}. 
. sort state 
{txt}
{com}. 
. *Deflate prices to 2002 dollars
. 
. 
. local p1 " p_goods p_all p_serv"
{txt}
{com}. 
. 
. foreach var of varlist `p1' p_icent_* p_ifcc_* p_yocent_* p_yofcc_* {c -(}
{txt}  2{com}. generate `var'_d=`var'/cpiu
{txt}  3{com}. replace `var'=`var'_d
{txt}  4{com}. drop `var'_d
{txt}  5{com}. {c )-}
{txt}(36,849 real changes made)
(36,849 real changes made)
(36,849 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(128 missing values generated)
(33,371 real changes made)
(128 missing values generated)
(33,371 real changes made)
(128 missing values generated)
(33,371 real changes made)
(128 missing values generated)
(33,371 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(128 missing values generated)
(33,371 real changes made)
(128 missing values generated)
(33,371 real changes made)
(128 missing values generated)
(33,371 real changes made)
(128 missing values generated)
(33,371 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(128 missing values generated)
(33,371 real changes made)
(128 missing values generated)
(33,371 real changes made)
(128 missing values generated)
(33,371 real changes made)
(128 missing values generated)
(33,371 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(33,499 real changes made)
(128 missing values generated)
(33,371 real changes made)
(128 missing values generated)
(33,371 real changes made)
(128 missing values generated)
(33,371 real changes made)
(128 missing values generated)
(33,371 real changes made)

{com}. 
. 
. save "$temp/parchild3.dta", replace  // Save data for additional merging
{txt}(note: file D:\users\llochner\Dropbox\JOINT PROJECTS\JPE_Child_Devp_2020\FINAL_Replication_CLMP_JPE\code\estimation\basics_rel_demand\temp_data/parchild3.dta not found)
file D:\users\llochner\Dropbox\JOINT PROJECTS\JPE_Child_Devp_2020\FINAL_Replication_CLMP_JPE\code\estimation\basics_rel_demand\temp_data/parchild3.dta saved

{com}. 
. 
. 
. 
. *******************************************************************
. ****************** E.  merge in fixed effects *********************
. *******************************************************************
. 
. sort mid 
{txt}
{com}. 
. merge m:1 mid using "$temp/ln_HCm_dat", keep(match master)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}           6,522
{txt}{col 9}from master{col 30}{res}           6,522{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}          30,327{txt}  (_merge==3)
{col 5}{hline 41}

{com}. tab _merge

                 {txt}_merge {c |}      Freq.     Percent        Cum.
{hline 24}{c +}{hline 35}
        master only (1) {c |}{res}      6,522       17.70       17.70
{txt}            matched (3) {c |}{res}     30,327       82.30      100.00
{txt}{hline 24}{c +}{hline 35}
                  Total {c |}{res}     36,849      100.00
{txt}
{com}. drop _merge
{txt}
{com}. 
. merge m:1 fid using "$temp/ln_HCf_dat", keep(match master)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}          19,790
{txt}{col 9}from master{col 30}{res}          19,790{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}          17,059{txt}  (_merge==3)
{col 5}{hline 41}

{com}. tab _merge

                 {txt}_merge {c |}      Freq.     Percent        Cum.
{hline 24}{c +}{hline 35}
        master only (1) {c |}{res}     19,790       53.71       53.71
{txt}            matched (3) {c |}{res}     17,059       46.29      100.00
{txt}{hline 24}{c +}{hline 35}
                  Total {c |}{res}     36,849      100.00
{txt}
{com}. drop _merge
{txt}
{com}. 
. 
. 
. *********************************************
. *** F.  SAVE THE FULL PARENT-CHILD DATA ****
. *********************************************
. sort kid year
{txt}
{com}. 
. save "$temp/psid_child.dta", replace
{txt}file D:\users\llochner\Dropbox\JOINT PROJECTS\JPE_Child_Devp_2020\FINAL_Replication_CLMP_JPE\code\estimation\basics_rel_demand\temp_data/psid_child.dta saved

{com}. 
. 
. **** Erase temporary datasets **** 
. 
. erase "$temp/parchild1.dta"
{txt}
{com}. erase "$temp/parchild2.dta"
{txt}
{com}. erase "$temp/parchild3.dta"
{txt}
{com}. erase "$temp/mother_occupation.dta"
{txt}
{com}. erase "$temp/father_occupation.dta"
{txt}
{com}. 
. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}D:\users\llochner\Dropbox\JOINT PROJECTS\JPE_Child_Devp_2020\FINAL_Replication_CLMP_JPE\code\estimation\basics_rel_demand\logs/2_create_child_data.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res} 9 Jul 2025, 17:15:46
{txt}{.-}
{smcl}
{txt}{sf}{ul off}